package socket;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server2 {
    private ServerSocket serverSocket;
    Server2()  {
        System.out.println("正在启动服务器。。。");
        try {
            serverSocket = new ServerSocket(8088);
            System.out.println("服务器启动完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        System.out.println("等待客户端链接。。");
        try {
            Socket socket = serverSocket.accept();
            System.out.println("一个客户端链接成功");
            InputStream is = socket.getInputStream();
            InputStreamReader ir = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(ir);
            String message;
            while ((message = br.readLine())!=null){
                System.out.println("客户端说："+message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Server2 server = new Server2();
        server.start();
    }

}
